﻿using Futaba.SBus.Telemetry;
using Futaba.SBus.Telemetry.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Futaba.SBus.Tests.Telemetry
{
	partial class SlotValueParserTests
	{

		[TestMethod, TestCategory("SBUS2"), TestCategory("SBUS2.Receiver")]
		public void ParseReceiver_Battery()
		{
			var target = SlotValueParser.DefaultInstance;
			var expected = 6.5;
			var parameter = GetParameter(_sensors, SensorType.Receiver, SensorValueType.Volt, "BATTERY");
			var parsingFlags = parameter.ParsingFlags;
			var valueMultiplier = parameter.ValueMultiplyer;

			var ctx = new SlotValueParserContext
			{
				CurrentValue = null,
				ParsingFlags = parsingFlags,
				Data = new byte[] { 0xC0, 0x41 },
				ValueMultiplicator = valueMultiplier
			};

			var actual = target.Parse(ctx);
			Assert.AreEqual(expected, actual);
		}

		[TestMethod, TestCategory("SBUS2"), TestCategory("SBUS2.Receiver")]
		public void ParseReceiver_ExtBattery()
		{
			var target = SlotValueParser.DefaultInstance;
			var expected = 14.4;
			var parameter = GetParameter(_sensors, SensorType.Receiver, SensorValueType.Volt, "EXTERNAL BATTERY");
			var parsingFlags = parameter.ParsingFlags;
			var valueMultiplier = parameter.ValueMultiplyer;

			var ctx = new SlotValueParserContext
			{
				CurrentValue = null,
				ParsingFlags = parsingFlags,
				Data = new byte[] { 0xC4, 0x90 },
				ValueMultiplicator = valueMultiplier
			};

			var actual = target.Parse(ctx);
			Assert.AreEqual(expected, actual);
		}

		[TestMethod, TestCategory("SBUS2"), TestCategory("SBUS2.Receiver")]
		public void ParseReceiver_State()
		{
			var target = SlotValueParser.DefaultInstance;
			var expected = 1;
			var parameter = GetParameter(_sensors, SensorType.Receiver, SensorValueType.Raw);
			var parsingFlags = parameter.ParsingFlags;
			var valueMultiplier = parameter.ValueMultiplyer;

			var ctx = new SlotValueParserContext
			{
				CurrentValue = null,
				ParsingFlags = parsingFlags,
				Data = new byte[] { 0x00, 0x01 },
				ValueMultiplicator = valueMultiplier
			};

			var actual = target.Parse(ctx);
			Assert.AreEqual(expected, actual);
		}

	}
}
